
$(function() {
	var name = document.getElementById("count");
	var password = document.getElementById("password");
	var usname = getCookie("name");
//	alert(usname);
	
	var us_password = getCookie("password");
	name.value=usname;
//	alert(us_password);
	password.value=us_password;
	$("#login").click(checkLogin);
	
});
function checkLogin(){
	//1.获取参数
	
	var name = $("#count").val().trim();
	var password = $("#password").val().trim();
	$("#count_span").html("");
	$("#password_span").html("");
	//2.检查格式
	var ok=true;
	if(name==""){
		ok=false;
		$("#count_span").html("用户名为空");
	}
	if(password==""){
		ok=false;
		$("#password_span").html("密码为空");
	}
	//获取选择框是否勾选
//	$("input:[type='checkbox']").is('checked');
	if(ok && document.getElementById("remember").checked){
		addCookie("password",password,2);
		addCookie("name",name,2);
		
	}

	//3.发送Ajax
	if(ok){
		$.ajax({
			url:base_path+"/login/login.do",
			type:"post",
			data:{"name":name,"password":password},
			dataType:"json",
			success:function(result){
				//result 就是服务器返回的json结果
				if(result.status==0){
					var user = result.data;//获取返回的user信息
					//写入cookie,2指的是存放两个小时
					addCookie("us_name",user.us_name,2);
					
					//js的跳转
					window.location.href ="index.html";
				} else if(result.status==1){
					//用户名错误
					
					$("#count_span").html(result.msg);
//					$("#count").html(result.msg);
				} else if(result.status==2){
					
					$("#password_span").html(result.msg);
				}
			},
			error:function(e){
				alert("登录异常");
			}
		});
	}
}
//function remember(name,password) {
//	addCookie("us_password",user.us_password,2)
//}